﻿using CleanArchitecture.Infrastructure.Entities.AdminUsers;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Text;

namespace CleanArchitecture.Infrastructure.DataMapping.AdminUsers
{
    /// <summary>
    /// Represents a customer-customer role mapping configuration
    /// </summary>
    public partial class AdminUserAdminRoleMappingMap : NowaEntityTypeConfiguration<AdminUserAdminRoleMapping>
    {
        #region Methods

        /// <summary>
        /// Configures the entity
        /// </summary>
        /// <param name="builder">The builder to be used to configure the entity</param>
        public override void Configure(EntityTypeBuilder<AdminUserAdminRoleMapping> builder)
        {
            builder.ToTable("adminuser_adminrole_mapping");
            builder.HasKey(mapping => new { mapping.FKAdminUserId, mapping.FKAdminRoleId });

            builder.Property(mapping => mapping.FKAdminUserId).HasColumnName("Fk_AdminUserId").IsRequired();
            builder.Property(mapping => mapping.FKAdminRoleId).HasColumnName("Fk_AdminRoleId").IsRequired();

            builder.HasOne(mapping => mapping.AdminUser)
                .WithMany(adminuser => adminuser.AdminuserAdminroleMappings)
                .HasForeignKey(mapping => mapping.FKAdminUserId)
                .IsRequired();

            builder.HasOne(mapping => mapping.AdminRole)
                .WithMany()
                .HasForeignKey(mapping => mapping.FKAdminRoleId)
                .IsRequired();

            builder.Ignore(mapping => mapping.Id);

            base.Configure(builder);
        }

        #endregion
    }
}
